package com.kuang.pet.controller;

import com.kuang.bascic.utils.AjaxResult;
import com.kuang.bascic.utils.PageList;
import com.kuang.pet.domain.Pet;
import com.kuang.quartaz.query.PetTypeQuery;
import com.kuang.pet.service.PetDetailService;
import com.kuang.pet.service.PetService;
import com.kuang.system.domain.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/pet")
public class PetController {
    @Autowired
    private PetService petService;
    @Autowired
    private PetDetailService detailService;
    @PostMapping
    public  PageList<Pet> selectPage(@RequestBody PetTypeQuery petTypeQuery){
        PageList<Pet> petPageList = petService.pageList(petTypeQuery);
       return petPageList;
    }
    @GetMapping
    public List<Pet> selectAllPet(){
         return petService.selectAllDepartment();
    }
    @PutMapping
    public AjaxResult addPet(@RequestBody Pet pet){
        try {
            petService.addDepartment(pet);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("网络错误");
        }
    }
    @PostMapping("/onsale")
    public AjaxResult onsale(@RequestBody Long[] ids){
        try {
            petService.onsale(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("网络错误");
        }
    }
    @GetMapping("/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id){
        try {
            Pet detil = petService.detil(id);
           return AjaxResult.me().setResultObj(detil);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("网络错误");
        }
    }
//    @GetMapping("/first")
//    public List<Menu> selectTree(){
//        return petService.selectTreeDepartment();
//    }




















}

